// OSCClass IOtest processing test sketch
// OSCClass version 1.0.1 (Arduino ver0014)
// need oscP5 Library
// Copyright (c) recotana(http://recotana.com).  All right reserved.

//click inside black window -> test circuit led on
//test circuit VR change -> window color change
//test circuit sw on -> window color black out
 
import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress arduinoAddress;

void setup() {
  size(400,400);
  frameRate(25);

  oscP5 = new OscP5(this,10000);
 
  arduinoAddress = new NetAddress("192.168.0.99",10000);
   background(0);  
}


void draw() {
 
}

void mousePressed() {

  OscMessage testMesssage1 = new OscMessage("/ard/led"); 
  testMesssage1.add(1); 
  
  oscP5.send( testMesssage1, arduinoAddress );

}



void oscEvent(OscMessage oscMessage) {

  print("received!");
  
  String address=oscMessage.addrPattern();
  print(" addrpattern: "+address);
  
  String typeTag = oscMessage.typetag();
  
  print(" typetag: "+typeTag);
  print(" ");
  
  if(address.equals("/ard/swich")){
    
    background(255);
    
  }
  else if(address.equals("/ard/pot")){
    
    int data=oscMessage.get(0).intValue();
    background(data,0,255-data);
    
  }
  else background(0);
  
  
  
  
  
  
  for(int i=0 ; i<typeTag.length() ; i++){

   switch( typeTag.charAt(i) ){
     
    case 'i': print( oscMessage.get(i).intValue() );
      break;

    case 'f': print( oscMessage.get(i).floatValue() );
      break;
 
    case 's': print( oscMessage.get(i).stringValue() );
      break;     
     
   }
  
    print(" ");
  }
  println("");
  
}
